// 联通图
class UnionFindSet {
    constructor(n) {
        this.fa = new Array(n).fill(-1).map((_, index) => index)
        this.count = n
    }

    find(x) {
        if (this.fa[x] !== x) {
            this.fa[x] = this.find(this.fa[x])
        }
        return this.fa[x]
    }

    union(x, y) {
        let fa_x = this.find(x)
        let fa_y = this.find(y)
        if (fa_x !== fa_y) {
            this.fa[fa_y] = fa_x;
            this.count--
        }
    }
}


const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n;
let initArr = [];
rl.on("line", (line)=>{
    if(n === undefined) {
        n = Number(line.trim())
    } else {
       let temp = line.trim().split(" ").map(Number)
        initArr.push(temp)

        if(initArr.length === n) {
            console.log(getResult(n, initArr));

            // clear
            n = undefined;
            initArr.length = 0
        }
    }
})

/**
 * 计算不联通的站点数
 * @param n {number} station count
 * @param initArr  {[[number]]}
 * @return {number} 不联通的站点数
 */
function getResult(n, initArr){
    const unionFindSet = new UnionFindSet(n);
    for (let i = 0; i < initArr.length; i++) {
        let arr = initArr[i]
        for (let j = i + 1; j < arr.length ; j++) {
            if(arr[j] === 1) unionFindSet.union(i, j)
        }
    }
    return unionFindSet.count;
}

